﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using InHD.model;
using InHD.commands;
using System.Windows.Input;

namespace InHD.viewmodels
{
    class CategoriesListViewModel:WorkspaceViewModel
    {
        #region Value Property
        private List<Category> _categoryRowCollection;
        private int _rowIndex = -1;
        public string commandExcute = string.Empty;
        private Category _category;
        #endregion

        #region Constructor
        public CategoriesListViewModel( List<Category> listCategory)
        {
            _categoryRowCollection = listCategory;
        }
        #endregion

        #region Presentation Property
        public List<Category> CategoryRowCollection
        {
            get
            {
                return _categoryRowCollection;
            }
            set
            {
                if (_categoryRowCollection != value)
                {
                    _categoryRowCollection = value;
                    OnPropertyChanged("CategoryRowCollection");
                }
            }
        }

        public int RowIndex
        {
            get
            {
                return this._rowIndex;
            }
            set
            {
                this._rowIndex = value;
                OnPropertyChanged("RowIndex");
            }
        }

        public Category SelectedCategory
        {
            get
            {
                return this._category;
            }
            set
            {
                if (value != null)
                {
                    this._category = value;
                }
            }
        }
        #endregion

        #region Command 
        private RelayCommand _viewCategoryCommand;
        public ICommand ViewCategoryCommand
        {
            get
            {
                if (_viewCategoryCommand == null)
                {
                    _viewCategoryCommand = new RelayCommand(
                        (param) => this.ViewCategory(),(param)=>CanView);
                }
                return _viewCategoryCommand;
            }
        }

        private RelayCommand _addNewCategoryCommand;
        public ICommand AddNewCategoryCommand
        {
            get
            {
                if (_addNewCategoryCommand == null)
                {
                    _addNewCategoryCommand = new RelayCommand(
                        (param) => this.AddNewCategory());
                }
                return _addNewCategoryCommand;
            }
        }
        #endregion

        #region Command Method
        void ViewCategory()
        {
            commandExcute = "View";
            OnRequestClose();
        }

        void AddNewCategory()
        {
            commandExcute = "Add";
            OnRequestClose();
        }
        #endregion

        public bool CanView { get { return this.SelectedCategory != null ? true : false; } }
    }
}
